import GoEasy from '@/common/goeasy/goeasy-2.2.4.min.js'

import Vue from 'vue'
import store from '@/store'
import IMService from "@/common/goeasy/imservice";

const state = {
    GoEasy: GoEasy,
    goEasy: null,
}

const getters = {
	
}

const actions = {
	initGoEasy({commit}, data) {
		return new Promise((resolve, reject) => {
			if(store.state.site.goeasy_open == 0 || store.state.site.goeasy_appkey == ''){
				resolve()
			}
			const goEasy = GoEasy.getInstance({
				host:"hangzhou.goeasy.io",//应用所在的区域地址: 【hangzhou.goeasy.io |singapore.goeasy.io】
				// appkey:"BC-941f143ffa86410399b9d27b8a17cca4",	// common key,
				appkey:store.state.site.goeasy_appkey,	// common key,
			    modules:["im"]
				// #ifdef APP-PLUS
				// true表示支持通知栏提醒，false则表示不需要通知栏提醒
			    ,allowNotification:true ,//仅有效于app,小程序和H5将会被自动忽略
				// #endif
			});
			commit('initGoEasy', goEasy)
			resolve()
		});
    },
	connectGoEasy({commit}, data) {
		return new Promise((resolve, reject) => {
			if(state.goEasy && state.goEasy.getConnectionStatus() === 'disconnected' && store.state.user.GoEasyUUID) {
				getApp().globalData.imService = new IMService(state.goEasy, state.GoEasy);
				if(store.state.user.GoEasyUUID){
					getApp().globalData.imService.connect({uuid: store.state.user.GoEasyUUID});
				}
			}
			resolve()
		});
	}
}

const mutations = {
    initGoEasy(state, goEasy) {
		state.GoEasy = GoEasy;
		state.goEasy = goEasy;
    }
}

export default {
    namespaced: true,
    state,
    actions,
    getters,
    mutations
}
